﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;

namespace Licenta1.Shapes
{
    [Serializable]
    class Rectangle : Shape
    {
        Expression parameters;
        public double width, length;
        public Point O;
        bool init = false;

        public Rectangle(Context con, Expression param)
            : base(con)
        {
            parameters = param;
            
        }

        public Rectangle(Context con, Point p, double w, double l)
            : base(con)
        {
            O = p;
            width = w;
            length = l;
            init = true;
        }

        private void CheckParameters()
        {
            try
            {
                ParameterList p_list = (ParameterList)parameters;

                O = (Point)p_list.FirstValue;
                p_list = (ParameterList)p_list.SecondValue;
                width = (double)p_list.FirstValue;
                length = (double)p_list.SecondValue;
                
            }
            catch (Exception e)
            {
                Console.WriteLine("Ex: " + e);
            }
            init = false;
            
        }

        

        public override string Display()
        {
            if (!init)
                CheckParameters();
            init = true;

            return "{R " + O.Display() + " W: " + width + " L: " + length + " }";
        }

        public override object Value
        {
            get
            {
                if (!init)
                    CheckParameters();
                return this;
            }
        }

        public override void Draw()
        {
            if (!init)
                CheckParameters();

            context.mp.objectsList.Add(this.GetClone());
        }

        public override object GetClone()
        {
            return new Rectangle(context, (Point)O.GetClone(), width, length); 
        }




    }
}